package cn.alex.sso.project.controller;

import cn.alex.sso.framework.annotations.OperatLog;
import cn.alex.sso.framework.constant.ModuleConstant;
import cn.alex.sso.framework.core.Result;
import cn.alex.sso.project.service.SysRoleClientService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 角色授权
 *
 * @author Alex
 * @date 2024/10/12 01:57
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/role/allow")
public class SysRoleAllowController {
    private final SysRoleClientService baseService;

    /**
     * 获取列表
     */
    @GetMapping("/getClientIdList")
    public Result getClientIdList(Long roleId) {
        return Result.ok(baseService.getClientIdListByRoleId(new ArrayList<Long>() {{
            add(roleId);
        }}));
    }

    /**
     * 保存
     */
    @PostMapping("/{roleId}")
    @OperatLog(module = ModuleConstant.ROLE, action = "授权")
    public Result change(@PathVariable Long roleId, @RequestBody List<Long> clientIdList) {
        baseService.change(roleId, clientIdList);
        return Result.ok();
    }
}
